package com.ipharma.interfaces.fingerprint;

import java.awt.Container;
//import com.bac.FPJni.*;

public class FingerPrint
{
 /* FPJni a;
  FP_VersionInfo ver;
  FP_AcqInfo acq;
  FP_AcqInfo liveacq;
  FP_AcqInfo matchacq;
  FP_Options opt;*/
  Container parent;
  FPErrMsg errMsg = new FPErrMsg();

  /**
   * Constructor
   */
  public FingerPrint( Container par )
  {
//    super();
    parent = par;
  }

  /* Create the FP_AcqInfo objects required for AcquireMaster */
 /* protected FP_AcqInfo createMasterAcq( FP_VersionInfo ver )
  {
    FP_AcqInfo acqInfo = new FP_AcqInfo();
    acqInfo.setNumberOut( 3 );

    FP_ImageDesc imgdesc[] = acqInfo.getImageDescArray();
    imgdesc[2] = new FP_ImageDesc();
    imgdesc[2].setImageType( FP_ImageDesc.FPIMG_MASTER );
    imgdesc[2].setOutputBufferMode( ver.getTemplateSize() );

    imgdesc[1] = new FP_ImageDesc();
    imgdesc[1].setImageType( FP_ImageDesc.FPIMG_CAPTURED );
    imgdesc[1].setOutputBufferMode( ver.getCapturedSize() );

    imgdesc[0] = new FP_ImageDesc();
    imgdesc[0].setImageType( FP_ImageDesc.FPIMG_ENHANCED );
    imgdesc[0].setOutputBufferMode( ver.getEnhancedSize() );

    return acqInfo;
  }

  /* Create the FP_AcqInfo objects required for Authenticate */
 /* protected FP_AcqInfo createLiveAcq( FP_VersionInfo ver )
  {
    FP_AcqInfo acqInfo = new FP_AcqInfo();
    acqInfo.setNumberOut( 1 );

    FP_ImageDesc imgdesc[] = acqInfo.getImageDescArray();
    imgdesc[0] = new FP_ImageDesc();
    imgdesc[0].setImageType( FP_ImageDesc.FPIMG_CAPTURED );
    imgdesc[0].setOutputBufferMode( ver.getCapturedSize() );

    return acqInfo;
  }

  /* Create the FP_AcqInfo objects required for FP_Auth_DisMatch*/
 /* protected FP_AcqInfo createMatchAcq( FP_VersionInfo ver )
  {
    FP_AcqInfo acqInfo = new FP_AcqInfo();
    acqInfo.setNumberOut( 2 );

    FP_ImageDesc imgdesc[] = acqInfo.getImageDescArray();
    imgdesc[0] = new FP_ImageDesc();
    imgdesc[0].setImageType( FP_ImageDesc.FPIMG_CAPTURED );
    imgdesc[0].setOutputBufferMode( ver.getCapturedSize() );
    imgdesc[1] = new FP_ImageDesc();
    imgdesc[1].setImageType( FP_ImageDesc.FPIMG_MASTER );
    imgdesc[1].setOutputBufferMode( ver.getTemplateSize() );

    return acqInfo;
  }

  /* Create the FPJni Object */
 /* protected void initFP( Container p )
  {
    try
    {
      a = new FPJni();
      ver = a.FPGetVersionInfo();
      acq = createMasterAcq( ver );
      liveacq = createLiveAcq( ver );
      matchacq = createMatchAcq( ver );
      a.FPInitialize( p, "User identificator" );
      opt = a.FPGetOptions();
      opt.setSystemModal( true );
      opt.setMatchingStrict( FP_Options.FP_MSTRICT_MEDIUM );
      a.FPSetOptions( opt );
      opt = a.FPGetOptions();
    }
    catch ( FPRuntimeException e )
    {
      errMsg.displayException( e.getMessage(), e.getErrorCode() );
    }
  }

  /**
	* Acquires a master image of a finger. This is image must be registered as master
	* @return the new fingerprint object
	*/
 /* public byte[] acqMaster()
  {
    byte[] l_FPrint = null;

//    resultLabel.setText( "" );
    try
    {
//      liveimg.setImageBuf( null );
//      liveimg.repaint();
//      acqimg.setImageBuf( null );
//      acqimg.repaint();
      if ( a == null )
      {
        initFP( parent );
      }
      boolean brc = a.FPIsDeviceConnected();
      if ( brc == false )
      {
        errMsg.displayException( "Device is not connected properly", -999 );
      }
      else
      {
        a.FPAcquireMaster( acq );

        if ( a.getErrorCode() != FPJni.FPWARN_ACQCAN )
        {
//          acqimg.setImageBuf( acq.getImageDesc( 1 ) );
          acq.getFeaturesExtracted();
          l_FPrint = acq.getImageDesc( 2 ).getOutputBuf();

        }
      }
    }
    catch ( FPRuntimeException e )
    {
//      acqimg.setImageBuf( null );
//      acqimg.repaint();
      errMsg.displayException( e.getMessage(), e.getErrorCode() );
    }
    catch ( RuntimeException e )
    {
//      acqimg.setImageBuf( null );
//      acqimg.repaint();
      errMsg.displayException( e.getMessage(), 0 );
    }
    return l_FPrint;
  }

  /**
	* Acquires a live image of a finger
	* @param pFPrint a finger print object
	* @return true if new image matches pFPrint
	*/
 /* public boolean acqLive( byte[] pFPrint )
  {
    try
    {
      if ( a == null )
      {
        initFP( parent );
      }

      FP_ImageDesc limgdesc = matchacq.getImageDesc( 1 );

      a.FPAuth_Extract( matchacq, null );
      if ( a.getErrorCode() != FPJni.FPWARN_ACQCAN )
      {
        FP_MatchInfo minfo = a.FPAuth_DisMatch( limgdesc.getOutputBuf(), pFPrint );
        if ( minfo.getMatch() )
          return true;
        else
          return false;
      }
    }
    catch ( FPRuntimeException e )
    {
      errMsg.displayException( e.getMessage(), e.getErrorCode() );
    }
    catch ( RuntimeException e )
    {
      errMsg.displayException( e.getMessage(), 0 );
    }
    return false;
  }*/

}